package com.zl.learning.io.test.com.socket.socket02;

/**
 * Created by zhaolei on 2017/4/27.
 */

import java.net.*;
import java.util.Enumeration;

/**
 * @author gxl
 */
public class GetLocalIps {
    public static void main(String[] args) throws SocketException {
        //get all local ips
        Enumeration<NetworkInterface> interfs = NetworkInterface.getNetworkInterfaces();
        while (interfs.hasMoreElements()) {
            NetworkInterface interf = interfs.nextElement();
            Enumeration<InetAddress> addres = interf.getInetAddresses();
            while (addres.hasMoreElements()) {
                InetAddress in = addres.nextElement();
                if (in instanceof Inet4Address) {
                    System.out.println("v4:" + in.getHostAddress());
                } else if (in instanceof Inet6Address) {
                    System.out.println("v6:" + in.getHostAddress());
                }
            }
        }
    }
}

